/**
 * @desc
 * 基础工具
 * Created by suweiming on 2018/3/29.
 */
/**
 * 生成ID
 * @param prefix
 * @returns {*}
 */
function fnGenId(prefix) {
    return (prefix || 'ID') + parseInt(Math.random() * 100000);
}

function _parseSearch(search) {
    var resultObj = {};
    var search = search || window.location.search;
    if (search && search.length > 1) {
        var search = search.indexOf('?') == 0 ? search.substring(1) : search;
        var items = search.split('&');
        for (var index = 0; index < items.length; index++) {
            if (!items[index]) {
                continue;
            }
            var kv = items[index].split('=');
            if (resultObj[kv[0]] != undefined) {
                if ($.isArray(resultObj[kv[0]])) {
                    // resultObj[kv[0]].push(decodeURI(kv[1])); // 解码
                    resultObj[kv[0]] += ',' + decodeURI(kv[1]);
                } else {
                    // var ar = [resultObj[kv[0]],decodeURI(kv[1])];
                    resultObj[kv[0]] += ',' + decodeURI(kv[1]);
                }
            } else {
                resultObj[kv[0]] = typeof kv[1] === "undefined" ? "" : decodeURI(kv[1]); // 解码
            }

        }
    }
    return resultObj;
}

function decodeObj(obj) {
    obj = obj || {};
    Object.keys(obj).map(function (item) {
        try {
            obj[item] = decodeURIComponent(((obj[item])));
        } catch (e) {
            console.log(e.message);
            obj[item] = obj[item];
        }
    });
    return obj;
}